#include "dicom/dicom_conf.h"
#include <gwbase/base/logging.h>

namespace dicom {

const int64_t kGiga = (1024L * 1024L * 1024L);

DicomConf* DicomConf::LoadConfFile(const std::string& path) {
  Conf* conf = new Conf();

  if (!conf->ParseFile(path).ok()) {
    LOG_ERROR << "faile to parse config file: " << path;
    delete conf;
    return NULL;
  }

  return new DicomConf(conf);
}

DicomConf::DicomConf(Conf* conf) : conf_(conf) {}

int DicomConf::GetListenPort() const {
  int port = static_cast<int>(conf_->GetInt64("server", "port", 3322));
  return port;
}

std::string DicomConf::GetPidFile() const {
  std::string server =
      conf_->GetString("server", "pid_file", "/var/run/dicom_gateway.pid");
  return server;
}

std::string DicomConf::GetDbDir() const {
  std::string dbdir = conf_->GetString("server", "local_db", "dicom_db");
  return dbdir;
}

std::string DicomConf::GetLogDir() const {
  std::string logdir = conf_->GetString("server", "log_dir", "dicom_log");
  return logdir;
}

std::string DicomConf::GetDataDir() const {
  std::string datadir =
      conf_->GetString("server", "local_storage", "dicom_data");
  return datadir;
}

int64_t DicomConf::GetMaxStorageSpace() const {
  int64_t space =
      conf_->GetSpaceSpec("server", "local_storage_space", 10L * kGiga);
  return space;
}

int DicomConf::GetUploadThreads() const {
  int threads =
      static_cast<int>(conf_->GetInt64("surcloud", "upload_threads", 2));
  return threads;
}

std::string DicomConf::GetCloudServer() const {
  std::string server =
      conf_->GetString("surcloud", "server", "https://open.surdoc.net");
  return server;
}
}
